#!/bin/bash
echo 'Stop jitsi admin services'
systemctl stop "*jitsi-admin*"
echo 'Reload jitsi-admin Services and Daemon'
systemctl daemon-reload
systemctl enable jitsi-admin_websocket.service
systemctl start jitsi-admin_websocket.service
systemctl restart jitsi-admin_websocket.service
systemctl is-active --quiet jitsi-admin_websocket.service && echo jitsi-admin_websocket.service is running

echo 'Reload Websocket services and daemon'
systemctl daemon-reload
systemctl enable jitsi-admin_websocket.service
systemctl start jitsi-admin_messenger.service
systemctl restart jitsi-admin_messenger.service
systemctl is-active --quiet jitsi-admin_messenger.service && echo jitsi-admin_messenger.service is running

echo 'Migrate Database'
php /var/www/jitsi-admin/bin/console doc:mig:mig --no-interaction
echo 'Migrate Database finished'
echo 'Clear Cache'
php /var/www/jitsi-admin/bin/console cache:clear
echo 'Successfully cleared cache'

echo 'Set correct directory permissions'
chown -R www-data:www-data /var/www/jitsi-admin/var/
chown -R www-data:www-data /var/log/websocket/
chown -R www-data:www-data /theme/
echo 'Create image directory'
mkdir -p /var/www/img_data/
ln -s  /var/www/img_data/ /var/www/jitsi-admin/public/uploads/images

echo 'Set apache config file'
a2dissite 000-default
a2ensite jitsiadmin
a2ensite jitsiadmin_ssl
echo 'Activate apache modules'
a2enmod proxy_fcgi proxy setenvif rewrite ssl
a2enconf php-fpm
echo 'start apache service'
systemctl reload apache2
systemctl restart apache2
systemctl restart php*-fpm



